package cn.joker.util;


import cn.joker.constant.Result;
import cn.joker.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.List;
import java.util.stream.Collectors;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    // 捕获所有异常并返回统一的错误信息
    @ExceptionHandler(Exception.class)
    public Result<String> handleException(Exception ex) {
        ex.printStackTrace();
        return Result.error("500", "系统内部错误，请联系管理员！");
    }

    @ExceptionHandler(BusinessException.class)
    public Result<String> handleBusinessException(Exception ex) {
        ex.printStackTrace();
        return Result.error("500", ex.getMessage());
    }
}
